package pl.com.like.sequoia.biojava.util;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;

import pl.com.like.sequoia.exceptions.LogicalException;
import pl.com.like.sequoia.exceptions.TechnicalException;
import pl.com.like.sequoia.model.bio.BioObjectAlign;
import pl.com.like.sequoia.model.bio.BioObjectHandler;
import pl.com.like.sequoia.model.bio.enums.BioObjectType;
import pl.com.like.sequoia.model.bio.enums.FileTypeEnum;
import pl.com.like.sequoia.model.bio.enums.SourceType;

public interface IConnectionHelper {

	/**
	 * Download file from given url
	 * 
	 * @param url which should be saved
	 * @param destFile destination file, where to should be saved
	 * @return
	 * @throws TechnicalException
	 * @throws LogicalException
	 */
	public File downloadFile(URL url, File destFile) throws TechnicalException, LogicalException;

	public abstract List<BioObjectHandler> getComparisonPair(String idComparison);

	/**
	 * get object form database
	 * 
	 * @param id
	 * @param fileType
	 * @return
	 * @throws LogicalException
	 */
	public abstract BioObjectHandler getObject(String id, FileTypeEnum fileType) throws LogicalException;

	public BioObjectAlign getSearchAlign(String idObject);

	/**
	 * get list of align results already counted for element with equal id with idObject
	 * 
	 * @param idObject
	 * @param fileType
	 * @param size
	 * @param extendedSearch
	 * @param firstResult
	 * @return
	 */
	public List<BioObjectAlign> getSearchAlignList(String idObject, FileTypeEnum fileType);

	public List<BioObjectHandler> getSearchList(String idObject, FileTypeEnum fileType, Integer size,
			Boolean extendedSearch, Integer firstResult);

	/**
	 * Check if given FileTypeEnum contain is supported by Genbank.
	 * 
	 * @param type given type for checking.
	 * @return if type is Genbank file, FASTA, or GENPEPT file
	 */
	public abstract Boolean isGenbankType(FileTypeEnum type);

	/**
	 * Check if given FileTypeEnum contain at least part of PDB information.
	 * 
	 * @param type given type for checking.
	 * @return if type is raw PDB, zipped PDB, or only PDB header, will return Boolean.TRUE
	 */
	public abstract Boolean isPDBFormat(FileTypeEnum type);

	/**
	 * read file from input stream and return content in array of strings
	 * 
	 * @param in input stream, from is read all information
	 * @return content of input Stream returned in array of strings
	 * @throws LogicalException if input string will not be accessible, will return LogicalException
	 */
	public abstract List<String> readFile(InputStream in) throws LogicalException;

	public abstract BioObjectAlign registerAlign(String idFile, FileTypeEnum fileType, File returnFile,
			SourceType type, BioObjectType bioType, BioObjectHandler bioA, BioObjectHandler bioB);

	/**
	 * Get temporary file, copy to repository and save info to database.
	 * 
	 * @param idFile
	 * @param fileType
	 * @param returnFile
	 * @param type
	 * @throws LogicalException
	 */
	public abstract BioObjectHandler registerFile(String idFile, FileTypeEnum fileType, File returnFile, SourceType type);
}